package com.common.tag;

import java.util.List;

public class Page<T> {

	public static final String PAGE_NO = "qm.pn";

	public static final String PAGE_LIMIT = "qm.limit";

	// 一页显示的记录数
	private int limit = 10;
	// 记录总数
	private int totalRows;
	// 当前页码
	private int pageNo;
	// 结果集存放List
	private List<T> resultList;

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public int getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public List<T> getResultList() {
		return resultList;
	}

	public void setResultList(List<T> resultList) {
		this.resultList = resultList;
	}

	
	
	public int getOffset() {
		return (pageNo - 1) * limit;
	}

	public int getEndIndex() {
		if (getOffset() + limit > totalRows) {
			return totalRows;
		} else {
			return getOffset() + limit;
		}
	}

	// 计算总页数
	public int getTotalPages() {
		int totalPages;
		if (totalRows % limit == 0) {
			totalPages = totalRows / limit;
		} else {
			totalPages = (totalRows / limit) + 1;
		}
		return totalPages;
	}

}
